// 模拟登录接口数据
const mockAuthData = {
  // 模拟用户数据
  users: [
    {
      id: '1',
      username: 'admin',
      password: 'admin123', // 实际项目中密码应该是加密存储的
      nickname: '管理员',
      avatar: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg',
      roles: ['admin', 'user'],
    },
    {
      id: '2',
      username: 'test',
      password: 'test123',
      nickname: '测试用户',
      avatar: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg',
      roles: ['user'],
    },
  ],
};

// 模拟登录请求
export const mockLogin = (username, password) => {
  return new Promise((resolve, reject) => {
    // 模拟网络延迟
    setTimeout(() => {
      const user = mockAuthData.users.find(
        (u) => u.username === username && u.password === password
      );
      
      if (user) {
        resolve({
          code: 200,
          message: '登录成功',
          data: {
            token: `mock_token_${Date.now()}`,
            userInfo: {
              id: user.id,
              username: user.username,
              nickname: user.nickname,
              avatar: user.avatar,
              roles: user.roles,
            },
          },
        });
      } else {
        reject({
          code: 401,
          message: '用户名或密码错误',
        });
      }
    }, 800);
  });
};

// 模拟获取用户信息
export const mockGetUserInfo = () => {
  return new Promise((resolve) => {
    // 模拟网络延迟
    setTimeout(() => {
      // 这里简单返回第一个用户作为示例
      const user = mockAuthData.users[0];
      resolve({
        code: 200,
        message: '获取用户信息成功',
        data: {
          id: user.id,
          username: user.username,
          nickname: user.nickname,
          avatar: user.avatar,
          roles: user.roles,
        },
      });
    }, 500);
  });
};

// 模拟退出登录
export const mockLogout = () => {
  return new Promise((resolve) => {
    // 模拟网络延迟
    setTimeout(() => {
      resolve({
        code: 200,
        message: '退出登录成功',
      });
    }, 300);
  });
};